/**
 * 
 * @author BJS aka Zephyr
 * @version 0.5
 * @date 2012-03-08
 * 
 */

var com;
if(!com) com = {};
else if( typeof com != 'object') throw new Error("com already exists and is not an object");
if(!com.zpyr) com.zpyr = {};
else if( typeof com.zpyr != 'object' ) throw new Error("com.zpyr already exists and is not an object");
if(!com.zpyr.Util) com.zpyr.Util = {};
else if( typeof com.zpyr.Util != 'object' ) throw new Error("com.zpyr.Util already exists and is not an object");

com.zpyr.Util.objToStr = {/*object*/};
com.zpyr.Util.strToObj = {/*str*/};
com.zpyr.Util.strToArray = {/*str*/};
com.zpyr.Util.objToArray = {/*object*/};
com.zpyr.Util.equals = {/*object , object*/};
com.zpyr.Util.clone = { /*obj , deep*/ };



/***************************************************************************************************/

com.zpyr.Util.objToStr = function(object) {
	if(typeof object != 'object')	return object;

	var retStr = "{" , pStr = "" , oStr = "";
	for( var p in object ) {
		
		if(typeof p == 'object') pStr = com.zpyr.Util.objToStr(p);
		else pStr = "'" + p + "'";
		
		if( typeof object[p] == 'function' ) continue;
		
		if(typeof object[p] == 'object') oStr = com.zpyr.Util.objToStr(object[p]);
		else oStr = "'" + object[p] + "'";
		retStr += pStr + ":" + oStr;
		retStr += ",";
	};
	if(retStr == "{") {
		return '';
	}
	retStr = retStr.substr(0 , retStr.length-1);
	retStr += "}";
	return retStr;
};

com.zpyr.Util.strToObj = function(str) {
	if(typeof object == 'object')	return str;
	var retObj = {};
	try {
		retObj = eval( "("+ str +")" );
	}
	catch(e) {
	}
	return retObj;
};

com.zpyr.Util.strToArray = function(str) {
	return com.zpyr.Util.objToArray( com.zpyr.Util.strToObj(str) );
};

com.zpyr.Util.objToArray = function(object) {
	if(typeof object != 'object') return object;
	
	var ret = new Array();
	for(var p in object) {
		ret.push( object[p] );
	}
	
	return ret;
};

com.zpyr.Util.equals = function(obja , objb) {
	if(obja == objb) return true;
	var propsInA = 0;
	for( var propName in obja ) {
		propsInA++;
		if(typeof obja[propName] == 'object') {
			if( !com.zpyr.Util.equals( obja[propName] , objb[propName] ) ) {
				return false;
			}
		}
		else if( typeof obja[propName] == 'function' ) {
		}
		else {
			if(obja[propName] != objb[propName]) return false;
		}
		
	};
	var propsInB = 0;
	for( var propName in objb ) propsInB++;
	
	if(propsInB != propsInA) return false;
	return true;
};

com.zpyr.Util.isEmail = function(strValue) {
	var regExp = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;
	
	if(!strValue) {
		return false;
	}
	if(!strValue.match(regExp)) {
		return false;
	}
	return true;
	
};

com.zpyr.Util.clone = function( obj , deep ) {
	var objectClone = new obj.constructor(); 
	for (var property in obj) 
		if (!deep) 
			objectClone[property] = obj[property]; 
		else if (typeof obj[property] == 'object') 
			objectClone[property] = obj[property].clone(deep); 
		else 
			objectClone[property] = obj[property]; 
		return objectClone; 
};
